package problema065;

import java.math.BigInteger;

public class ConvergentsOfe {
	
	static int[] numero = new int[100];
	static BigInteger[] cache = new BigInteger[100];
	static BigInteger cero = new BigInteger("0");
	static BigInteger diez = new BigInteger("10");

	public static void main(String[] args){
		sumaNum();
	}
	
	public static void sumaNum(){
		llenarVec();
		for(int i = 2; i < cache.length; i++)cache[i] = cero;
		cache[0] = new BigInteger(Integer.toString(numero[0]));
		int num1 = (numero[0] * numero[1] + 1) / numero[1];
		cache[1] = new BigInteger(Integer.toString(num1));
		BigInteger num = dameNum(numero.length-1);
		int res = 0;
		while(!num.equals(cero)){
			res += num.mod(diez).intValue();
			num = num.divide(diez);
		}
		System.out.println(res);
	}
	
	
	public static BigInteger dameNum(int pos){
		if(!cache[pos].equals(cero)) return cache[pos];
		BigInteger act = new BigInteger(Integer.toString(numero[pos]));
		cache[pos] = act.multiply(dameNum(pos-1)).add(dameNum(pos-2));
		return cache[pos];
	}
	
	public static void llenarVec(){
		numero[0] = 2;
		numero[1] = 1;
		int k = 1;
		for(int i = 2; i < numero.length; i++){
			if(((i+1) % 3) == 0){
				numero[i] = 2*k;
				k++;
				continue;
			}
			numero[i] = 1;
		}
	}
	
	
}
